/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package smartgrid;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

import java.io.Serializable;
/**
 * Classe que representa um preço.
 */
public class Price implements Serializable {
	public Price() {
	}
	
	public static Price loadPriceByORMID(int ID) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadPriceByORMID(session, ID);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price getPriceByORMID(int ID) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return getPriceByORMID(session, ID);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price loadPriceByORMID(int ID, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadPriceByORMID(session, ID, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price getPriceByORMID(int ID, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return getPriceByORMID(session, ID, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price loadPriceByORMID(PersistentSession session, int ID) {
		try {
			return (Price) session.load(smartgrid.Price.class, new Integer(ID));
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price getPriceByORMID(PersistentSession session, int ID) {
		try {
			return (Price) session.get(smartgrid.Price.class, new Integer(ID));
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price loadPriceByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) {
		try {
			return (Price) session.load(smartgrid.Price.class, new Integer(ID), lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price getPriceByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) {
		try {
			return (Price) session.get(smartgrid.Price.class, new Integer(ID), lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price[] listPriceByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return listPriceByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price[] listPriceByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return listPriceByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price[] listPriceByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From smartgrid.Price as Price");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Price[]) list.toArray(new Price[list.size()]);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price[] listPriceByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From smartgrid.Price as Price");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Price[]) list.toArray(new Price[list.size()]);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price loadPriceByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadPriceByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price loadPriceByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadPriceByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price loadPriceByQuery(PersistentSession session, String condition, String orderBy) {
		Price[] prices = listPriceByQuery(session, condition, orderBy);
		if (prices != null && prices.length > 0)
			return prices[0];
		else
			return null;
	}
	
	public static Price loadPriceByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		Price[] prices = listPriceByQuery(session, condition, orderBy, lockMode);
		if (prices != null && prices.length > 0)
			return prices[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePriceByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return iteratePriceByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iteratePriceByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return iteratePriceByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iteratePriceByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From smartgrid.Price as Price");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iteratePriceByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From smartgrid.Price as Price");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Price loadPriceByCriteria(PriceCriteria priceCriteria) {
		Price[] prices = listPriceByCriteria(priceCriteria);
		if(prices == null || prices.length == 0) {
			return null;
		}
		return prices[0];
	}
	
	public static Price[] listPriceByCriteria(PriceCriteria priceCriteria) {
		return priceCriteria.listPrice();
	}
	
	public static Price createPrice() {
		return new smartgrid.Price();
	}
	
	public boolean save() {
		try {
			smartgrid.SmartgridPersistentManager.instance().saveObject(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean delete() {
		try {
			smartgrid.SmartgridPersistentManager.instance().deleteObject(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean refresh() {
		try {
			smartgrid.SmartgridPersistentManager.instance().getSession().refresh(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean evict() {
		try {
			smartgrid.SmartgridPersistentManager.instance().getSession().evict(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean deleteAndDissociate() {
		try {
			if(getTariff_Prices_role() != null) {
				getTariff_Prices_role().price_Prices_role.remove(this);
			}
			
			return delete();
		}
		catch(Exception e) {
			return false;
		}
	}
	
	public boolean deleteAndDissociate(org.orm.PersistentSession session) {
		try {
			if(getTariff_Prices_role() != null) {
				getTariff_Prices_role().price_Prices_role.remove(this);
			}
			
			try {
				session.delete(this);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			return false;
		}
	}
	
	private void this_setOwner(Object owner, int key) {
		if (key == smartgrid.ORMConstants.KEY_PRICE_TARIFF_PRICES_ROLE) {
			this.Tariff_Prices_role = (smartgrid.Tariff) owner;
		}
	}
	
	org.orm.util.ORMAdapter _ormAdapter = new org.orm.util.AbstractORMAdapter() {
		public void setOwner(Object owner, int key) {
			this_setOwner(owner, key);
		}
		
	};
	
	private int ID;
	
	private smartgrid.Tariff Tariff_Prices_role;
	
	private int StartHour;
	
	private int StartMinute;
	
	private float Euros;
	
	private int EndHour;
	
	private int EndMinute;
	
	private void setID(int value) {
		this.ID = value;
	}
	
	public int getID() {
		return ID;
	}
	
	public int getORMID() {
		return getID();
	}
	
	/**
	 * Hora a partit da qual o preço se aplica.
	 */
	public void setStartHour(int value) {
		this.StartHour = value;
	}
	
	/**
	 * Hora a partit da qual o preço se aplica.
	 */
	public int getStartHour() {
		return StartHour;
	}
	
	/**
	 * Hora a partir da qual o preço deixa de ser aplicado.
	 */
	public void setStartMinute(int value) {
		this.StartMinute = value;
	}
	
	/**
	 * Hora a partir da qual o preço deixa de ser aplicado.
	 */
	public int getStartMinute() {
		return StartMinute;
	}
	
	public void setEndHour(int value) {
		this.EndHour = value;
	}
	
	public int getEndHour() {
		return EndHour;
	}
	
	public void setEndMinute(int value) {
		this.EndMinute = value;
	}
	
	public int getEndMinute() {
		return EndMinute;
	}
	
	/**
	 * Valor do preço em euros.
	 */
	public void setEuros(float value) {
		this.Euros = value;
	}
	
	/**
	 * Valor do preço em euros.
	 */
	public float getEuros() {
		return Euros;
	}
	
	public void setTariff_Prices_role(smartgrid.Tariff value) {
		if (Tariff_Prices_role != null) {
			Tariff_Prices_role.price_Prices_role.remove(this);
		}
		if (value != null) {
			value.price_Prices_role.add(this);
		}
	}
	
	public smartgrid.Tariff getTariff_Prices_role() {
		return Tariff_Prices_role;
	}
	
	/**
	 * This method is for internal use only.
	 */
	private void setORM_Tariff_Prices_role(smartgrid.Tariff value) {
		this.Tariff_Prices_role = value;
	}
	
	private smartgrid.Tariff getORM_Tariff_Prices_role() {
		return Tariff_Prices_role;
	}
	
	/**
	 * Retorna o objecto serializado no formato JSon.
	 */
	public String getJson() {
		//TODO: Implement Method
		throw new UnsupportedOperationException();
	}
	
	public String toString() {
		return String.valueOf(getID());
	}
	
}
